<?php

require_once 'SQLHelper.class.php';

$time_start = ' 05:00:00';
$time_end = ' 09:00:00';
$tody_end = ' 23:59:59';
$today = date('y-m-d');
$now = date('y-m-d H:i:s');
$time = $today . $time_end;

$startTime = $today . $time_start;
$endTime = $today . $tody_end;
if(strtotime($time) < strtotime($now)) {
	$sqlHelper = new SQLHelper();

	// 获取所有人员名单
	$sql = "select username from user";
	$arr = $sqlHelper->exc_dql2($sql);
	$user_all = array();
	foreach($arr as $val) {
		$user_all[] = $val['username'];
	}

	// 获取当天已签到人员名单
	$sql = "select userid  from signlog where signTime > '$startTime' and signTime < '$endTime'";
	$arr = $sqlHelper->exc_dql2($sql);
	$user_signed = array();
	foreach($arr as $val) {
		$user_signed[] = $val['userid'];
	}

	$count = 0;
	foreach($user_all as $user) {
		if(!in_array($user, $user_signed)) {
			$sql_dml = "insert into signlog (userid,signTime,comment, times) values('$user',now(), '已迟到，系统已自动签到！请及时上交罚款！', 0)";
			$sqlHelper->exc_dml($sql_dml);
			$count++;
		}
	}



	$sqlHelper->connect_close();
	echo date('y-m-d') . ",共有" . $count . "人未签到!\r\n";

	exit;
}
